package com.dong.factoryMode.service.impl;

import com.alibaba.fastjson.JSON;

import com.dong.factoryMode.prepare.goods.DeliverReq;
import com.dong.factoryMode.prepare.goods.GoodsService;
import com.dong.factoryMode.service.ICommodity;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author DongJiaQi
 * @create 2022/12/20 10:10
 * @Description: 实物商品发放接口
 */
@Slf4j
public class GoodsCommodityImpl implements ICommodity {
    private GoodsService goodsService = new GoodsService();
    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryUserName(uId));
        deliverReq.setUserPhone(queryUserPhoneNumber(uId));
        deliverReq.setSku(commodityId);
        deliverReq.setOrderId(bizId);
        deliverReq.setConsigneeUserName(extMap.get("consigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("consigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("consigneeUserAddress"));
        Boolean isSuccess = goodsService.deliverGoods(deliverReq);
        log.info("请求参数[实物商品] => uId：{} commodityId：{} bizId：{} extMap：{}", uId, commodityId, bizId, JSON.toJSON(extMap));
        log.info("测试结果[实物商品]：{}", isSuccess);
        if (!isSuccess) {
            throw new RuntimeException("实物商品发放失败");
        }
    }

    private String queryUserName(String uId) {
        return "花花";
    }
    private String queryUserPhoneNumber(String uId) {
        return "15200101232";
    }
}
